// BCBrunnstromPage.cpp : implementation file
//

#include "stdafx.h"
#include "../Frame/GYWalkAidApp.h"
#include "BCBrunnstromPage.h"
#include "../Common/LinkComboBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBCBrunnstromPage dialog
static INPUT_FIELD_INFO s_InputFieldArray1[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray2[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray3[] = 
{
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		CBCBrunnstromPage::ScoreFieldsCheck,	CBCBrunnstromPage::ScoreFieldsCheck	},
};


CBCBrunnstromPage::CBCBrunnstromPage(CWnd* pParent, BOOL bBigRes) : CScrollPage(bBigRes ? CBCBrunnstromPage::IDD : CBCBrunnstromPage::SD_IDD, pParent)
, m_edtHolden101(&m_InputFieldArray1[0]),	m_edtHolden201(&m_InputFieldArray2[0]),	m_edtHolden301(&m_InputFieldArray3[0])
{
	//{{AFX_DATA_INIT(CBCBrunnstromPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	LPVOID pCtrl = NULL;
	DWORD dwControlType = IBT_NoneType;
	for(int i = 0; i < INPUT_EDIT_CTRL_COUNT; i++)
	{
		pCtrl = m_InputFieldArray1[i].pLinkCtrl;
		dwControlType = m_InputFieldArray2[i].dwCtrlType;
		memcpy(&m_InputFieldArray1[i], &s_InputFieldArray1[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray1[i].pLinkCtrl = pCtrl;
		m_InputFieldArray1[i].dwCtrlType = dwControlType;
		
		pCtrl = m_InputFieldArray2[i].pLinkCtrl;
		dwControlType = m_InputFieldArray2[i].dwCtrlType;
		memcpy(&m_InputFieldArray2[i], &s_InputFieldArray2[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray2[i].pLinkCtrl = pCtrl;
		m_InputFieldArray2[i].dwCtrlType = dwControlType;
		
		pCtrl = m_InputFieldArray3[i].pLinkCtrl;
		dwControlType = m_InputFieldArray3[i].dwCtrlType;
		memcpy(&m_InputFieldArray3[i], &s_InputFieldArray3[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray3[i].pLinkCtrl = pCtrl;
		m_InputFieldArray3[i].dwCtrlType = dwControlType;
	}
}


void CBCBrunnstromPage::DoDataExchange(CDataExchange* pDX)
{
	CScrollPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBCBrunnstromPage)
	DDX_Control(pDX, IDC_EDIT_SCORE1, m_edtHolden101);
	DDX_Control(pDX, IDC_EDIT_SCORE2, m_edtHolden201);
	DDX_Control(pDX, IDC_EDIT_SCORE3, m_edtHolden301);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBCBrunnstromPage, CScrollPage)
	//{{AFX_MSG_MAP(CBCBrunnstromPage)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBCBrunnstromPage message handlers

void CBCBrunnstromPage::OnSize(UINT nType, int cx, int cy) 
{
	CScrollPage::OnSize(nType, cx, cy);
	
	//...
}

BOOL CBCBrunnstromPage::ClearData()
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_BRUNN_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_BRUNN_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_BRUNN_DATE_3);
	
	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	return PageClearData(ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, ARRAY_ELE_COUNT(apDateLabel));
}

int CBCBrunnstromPage::SaveData(CString strMRN, int nDiagSN, BOOL bIsDraft)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	return PageSaveData(strMRN, nDiagSN, bIsDraft, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBrunnstromPage::ScoreFieldsCheck(LPVOID pParam)
{
	CBCBrunnstromPage* pParent = NULL;
	INPUT_FIELD_INFO* pFieldInfo = (INPUT_FIELD_INFO*)pParam;
	
	if(pFieldInfo->dwCtrlType == IBT_EditBox)
	{
		CLinkEdit* pEdit = (CLinkEdit*)pFieldInfo->pLinkCtrl;
		if(pEdit)
			pParent = (CBCBrunnstromPage*)pEdit->GetParent();
	}
	else if(pFieldInfo->dwCtrlType == IBT_ComboBox)
	{
		CLinkComboBox* pCombo = (CLinkComboBox*)pFieldInfo->pLinkCtrl;
		if(pCombo)
			pParent = (CBCBrunnstromPage*)pCombo->GetParent();
	}
	else
	{
		ASSERT(FALSE);
	}
	
	if(pParent == NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}
	
	return PageScoreFieldsCheck(pParam, 0, 5, pParent->m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBrunnstromPage::ShowTableDataWithStartCol(CString strMRN, int nDiagSN, int nStartCol)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_BRUNN_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_BRUNN_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_BRUNN_DATE_3);
	
	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	return PageShowTableData(strMRN, nDiagSN, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, nStartCol);
}

BOOL CBCBrunnstromPage::ShowTableData(CString strMRN, int nDiagSN)
{
	return ShowTableDataWithStartCol(strMRN, nDiagSN, 2);
}

BOOL CBCBrunnstromPage::SetLastColTitile(CString strDate, int nDiagSN)
{
	CWnd* apDateLabel[3] = {0};
	apDateLabel[2] = GetDlgItem(IDC_STATIC_BRUNN_DATE_3);
	
	CString astrDate[3];
	astrDate[2] = strDate;
	
	CWnd* apDiagSNArray[3] = {0};
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	int anDiagSN[3] = {0};
	anDiagSN[2] = nDiagSN;
	
	return PageShowColTitle(apDateLabel, astrDate, apDiagSNArray, anDiagSN, ARRAY_ELE_COUNT(apDateLabel));
}

BOOL CBCBrunnstromPage::EnableInputControls(BOOL bEnable)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	return PageEnableInputControls(bEnable, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBrunnstromPage::IsPageCurDayBlank()
{
	return CScrollPage::PageIsAllInputBlank(m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}
